<template>
    <div class="user-list-dialog">
        <div class="user-list">
            <div class="user-header">私聊</div>

            <div class="firend-list">
                <div class="firend-item" @click="emits('change', item.user.id)" v-for="item in list" :key="item.id">
                    <img class="avatar" :src="item.user.avatar || _defaultAvatar_" />
                    <div class="info">
                        <div class="top">
                            <div class="username">
                                {{ item.user.nickname }}
                            </div>

                            <div class="unread-dot" v-if="item.unread">
                                {{ item.unread }}
                            </div>

                        </div>
                        <div class="bottom">
                            <div class="content">{{ item.message }}</div>
                            <div class="time">{{ timeDifference(item.createtime) }}</div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</template>
<script setup>
const props = defineProps({
    list: {
        type: Array,
        default: () => []
    }
})

const emits = defineEmits(['change']);
</script>
<style lang="scss" scoped>
.user-list-dialog {
    position: fixed;
    bottom: 80px;
    right: 20px;
    background-color: rgba(0, 0, 0, .5);
    backdrop-filter: blur(20px);
    border-radius: 8px;
    z-index: 999;
    width: 320px;
    height: 400px;

    .user-list {
        padding: 0 10px;

        .user-header {
            color: #fff;
            padding: 10px 0;
        }

        .firend-list {
            height: 360px;
            overflow-y: auto;
            scrollbar-width: none;

            &::-webkit-scrollbar {
                display: none;
            }

            .firend-item {
                display: flex;
                align-items: center;
                padding: 10px;
                border-radius: 10px;
                cursor: pointer;

                &:hover {
                    background-color: rgba(255, 255, 255, .1);
                }

                .avatar {
                    width: 40px;
                    height: 40px;
                    border-radius: 50%;
                    margin-right: 10px;
                    object-fit: cover;
                    flex-shrink: 0;
                }

                .info {
                    width: 230px;
                    color: #fff;
                    font-size: 14px;
                    padding-left: 5px;

                    .top {
                        position: relative;
                        display: flex;
                        margin-left: auto;

                        .username {
                            width: 200px;
                            white-space: nowrap;
                            overflow: hidden;
                            text-overflow: ellipsis;
                        }

                        .unread-dot {
                            display: flex;
                            align-items: center;
                            justify-content: center;
                            position: absolute;
                            top: 0;
                            right: 0;
                            width: 16px;
                            height: 16px;
                            font-size: 12px;
                            background-color: #ff0000;
                            color: #fff;
                            border-radius: 50%;
                        }
                    }

                    .bottom {
                        width: 100%;
                        display: flex;
                        margin-top: 8px;
                    }

                    .content {
                        width: 100%;
                        white-space: nowrap;
                        overflow: hidden;
                        text-overflow: ellipsis;
                        margin-right: 10px;
                    }

                    .time {
                        margin-left: auto;
                        flex-shrink: 0;
                    }
                }

            }
        }
    }
}
</style>